package com.huarun.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;


import com.alibaba.fastjson.JSONObject;

public class ImageUtil {
	
	public static String identifyImageLZ(String imageStr) throws Exception {
		
		URI uri = new URI("https://v2-api.jsdama.com/upload");
		String postBody = "{\"softwareId\":17089,\"softwareSecret\":\"ZZohaV8LezAemEdiIHfTMdmmsUjBcw91I2ymYEBF\"" + 
				",\"username\":\"vipwangtao999\",\"password\":\"Wt985200...\",\"captchaData\":\""+imageStr+"\",\"captchaType\":1318,\"captchaMinLength\":1,\"captchaMaxLength\":4}";
//		System.out.println(postBody);
		HttpClient httpClient = HttpClient.newBuilder()
		        .build();
		HttpRequest httpPostRequest = HttpRequest.newBuilder(uri)
				.header("User-Agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36")
				.header("Accept","application/json, text/javascript, */*; q=0.01")
//				.header("Connection","keep-alive")
    			.header("Content-Type", "text/json")
    			.POST(HttpRequest.BodyPublishers.ofString(postBody))
                .build();
		HttpResponse<String> response =
				httpClient.send(httpPostRequest, HttpResponse.BodyHandlers.ofString());
//		System.out.println(response.version());
//		System.out.println(response.statusCode());
		System.out.println(response.body());
		String result = JSONObject.parseObject(response.body()).getJSONObject("data").getString("recognition");
        return result;
	}
	

}
